Java and the Waba Toolkit by Al Williams Listing One // RPN calculator for CE or Palm // Al Williams import waba.ui.*; import waba.fx.*; import waba.util.*; public class alcalc extends MainWindow { final int stacksize=4; // Set stack depth // Buttons and display Button btns[] = new Button[18]; Label led = new Label("0.0",Label.RIGHT); // This is the stack float stack[] = new float[stacksize]; float dp=0.0f; // decimal point scaling int sp=0; // stack pointer int lift=0; // stack lift (new entry) flag // Scale factors for the current window int hi; int wid; // Set incr==1 to increment; -1 to decrement // circularizes based on stacksize int addsp(int sp,int incr) { if (incr==-1 && sp==0) return stacksize-1; if (incr==1 && sp==stacksize-1) return 0; return sp+incr; } // set up a button // x,y are row and column NOT pixels // width is 1 for single-width, 2 for double width void setBtn(int i,String lbl,int x,int y, int width) { btns[i]=new Button(lbl); btns[i].setRect(x*(wid+5),y*(hi+5),width*wid,hi); add(btns[i]); } // Set up all the work public void onStart() { Rect r; r=getRect(); hi=r.height/7; wid=r.width/5; stack[sp]=0; // display led.setRect(0,0,r.width-10,hi); add(led); // set up all buttons setBtn(0,"0",1,4,1); setBtn(1,"1",0,3,1); setBtn(2,"2",1,3,1); setBtn(3,"3",2,3,1); setBtn(4,"4",0,2,1); setBtn(5,"5",1,2,1); setBtn(6,"6",2,2,1); setBtn(7,"7",0,1,1); setBtn(8,"8",1,1,1); setBtn(9,"9",2,1,1); setBtn(10,"Enter",0,5,2); setBtn(11,"+",3,1,1); setBtn(12,"-",3,2,1); setBtn(13,"*",3,3,1); setBtn(14,"/",3,4,1); setBtn(15,"+/-",0,4,1); setBtn(16,".",2,4,1); setBtn(17,"x<>y",2,5,2); } // display number at top of stack void disp(int newlift) { led.setText(waba.sys.Convert.toString(stack[sp])); lift=newlift; } // Handle key pressses public void onEvent(Event event) { int i=-1; int leaddp=0; // leading decimal point? int neg=1; // 1 means positive number if (event.type==KeyEvent.KEY_PRESS) { KeyEvent kevent = (KeyEvent)event; if (kevent.key==IKeys.ENTER) kevent.key='\n'; // Enter key // convert key to button # String keys="0123456789\n+-*/ ."; for (i=0;iy case 17: float tmp; i=addsp(sp,-1); tmp=stack[sp]; stack[sp]=stack[i]; stack[i]=tmp; disp(1); break; } } } } Listing Two @echo off rem compile program, build warp files and launchers javac *.java warp c /q alcalc *.class exegen /q /i icon.bmp alcalc alcalc alcalc echo To test program: echo java waba.applet.Applet alcalc 4